 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
import { OutMineEntity } from "GameLoop/WorldState/EntityManager/Entitys";
 
import { priority } from "utils/constants/definetypes";
import { TaskHelper } from "utils/task/TaskHelper";
 
/**
 * 暂停资源房任务
 */
export class PauseRoomTaskDecision< T extends "team"|"room"="team"|"room"> extends ABaseDecision<T>
{
    
    public isExpired(event: PauseEvent, region: string): boolean 
    {
         
         
        return true;
    }
    public makeTask(event: PauseEvent, region: string): IDecisionCode<T>|false
    {
        // 暂停此房间的所有任务
        const room = Game.rooms[event.region] as Required<Room>;
        room.log('info',event.room,`暂停此房间的所有任务`);
        if(event.creepTaskType)
        {
            // 普通房间只暂停指定类型。比如采集
            if(typeof event.creepTaskType == "string")
            {

                
                room.getTaskByType("creep",(e:ITaskDeclare["creep"])=>e.data.room == event.room && e.data.type == event.creepTaskType).forEach(e=>room.pauseTask(e,event.pause));
            }
            else   
            {
                room.getTaskByType("creep",(e:ITaskDeclare["creep"])=>e.data.room == event.room && (event.creepTaskType as CreepTaskType[]) .includes(e.data.type)).forEach(e=>room.pauseTask(e,event.pause));
            }
            
        }
        else 
        {
            // 其他房间暂停，比如中央房就要暂停采集 守护
            room.getTaskByType("creep",(e:ITaskDeclare["creep"])=>e.data.room == event.room).forEach(e=>room.pauseTask(e,event.pause));
            room.getTaskByType("team",(e:ITaskDeclare["team"])=>e.data.room == event.room).forEach(e=>room.pauseTask(e,event.pause));
    
            room.getTaskByType("creep",(e:ITaskDeclare["creep"])=>room.getEntityByID<OutMineEntity>(e.id)?.roomName == event.room).forEach(e=>room.pauseTask(e,event.pause));
        }
       
        
        return false;
        // return code
    }
     
 
}